﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using OrderCms.DataAccess;

namespace 订单分流.Api
{
	// Token: 0x0200000A RID: 10
	internal class QuerySql
	{
		// Token: 0x0600002E RID: 46 RVA: 0x00005868 File Offset: 0x00003A68
		public static DataTable GetUser_GroupDt()
		{
			return DbHelper.GetDataTable(CommandType.Text, "SELECT * FROM [dbo].[User_Group]", new DbParameter[0]);
		}

		// Token: 0x0600002F RID: 47 RVA: 0x0000588C File Offset: 0x00003A8C
		public static DateTime GetLastUpTime()
		{
			DataTable dt = DbHelper.GetDataTable(CommandType.Text, "SELECT top 1 CreateTime FROM [dbo].[User_Group] WITH(NOLOCK) Order by CreateTime desc", new DbParameter[0]);
			return Convert.ToDateTime(dt.Rows[0][0]);
		}

		// Token: 0x06000030 RID: 48 RVA: 0x000058C8 File Offset: 0x00003AC8
		public static DataTable GetUser_SupCloseTimeDt()
		{
			return DbHelper.GetDataTable(CommandType.Text, "SELECT [ID],[CloseSupTime],[SupIsActive],[User_GroupId],[SupAccount] FROM [OrderCms].[dbo].[User_Sup] WITH(NOLOCK)", new DbParameter[0]);
		}

		// Token: 0x06000031 RID: 49 RVA: 0x000058EC File Offset: 0x00003AEC
		public static void UpdateSupIsActive(int ID, bool SupIsActive, string SupAccount, int User_GroupId)
		{
			bool flag = !SupIsActive;
			if (flag)
			{
				QuerySql.InsertWanrning(User_GroupId, "[" + SupAccount + "]已到关闭时间，已自动[关闭]．");
			}
			else
			{
				QuerySql.InsertWanrning(User_GroupId, "[" + SupAccount + "]已到开启时间，已自动[开启]．");
			}
			DbHelper.ExecuteNonQuery(CommandType.Text, string.Concat(new object[]
			{
				"UPDATE [OrderCms].[dbo].[User_Sup] SET SupIsActive='",
				SupIsActive.ToString(),
				"' WHERE ID=",
				ID
			}));
		}

		// Token: 0x06000032 RID: 50 RVA: 0x0000596C File Offset: 0x00003B6C
		public static void InsertWanrning(int User_GroupId, string WarningStr)
		{
			SqlParameter[] Parameters = new SqlParameter[]
			{
				new SqlParameter("@User_GroupId", SqlDbType.Int),
				new SqlParameter("@WarningStr", SqlDbType.VarChar)
			};
			Parameters[0].Value = User_GroupId;
			Parameters[1].Value = WarningStr;
			StringBuilder sql = new StringBuilder();
			sql.AppendLine("INSERT INTO [dbo].[Wanrning] ([User_GroupId],[WarningStr]) VALUES (@User_GroupId,@WarningStr)");
			int num = DbHelper.ExecuteNonQuery(CommandType.Text, sql.ToString(), Parameters);
		}
	}
}
